﻿<%@ WebHandler Language="C#" Class="ZSWorktimeReport" %>

using System;
using System.Web;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using System.Web.SessionState;
using System.IO;
using ReportBusiness;

public class ZSWorktimeReport : IHttpHandler
{
    public bool IsReusable { get { return false; } }
    private uMESCommonMethod cm = new uMESCommonMethod();
    private uMESReportOracleDAL dal = new uMESReportOracleDAL();
    private uMESWorkTimeReportBusiness wipDll = new uMESWorkTimeReportBusiness();
    public void ProcessRequest(HttpContext context)
    {
        //查询员工信息
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetEmpInfo")
        {
            string sql = @" SELECT e.employeeid,e.employeename,e.fullname,f.factoryname,f.factoryid,
                                   w.workcentername,w.workcenterid,s.shiftname,s.shiftid,t.teamname,t.teamid,rd.rolename
                            FROM employee e
                            LEFT JOIN Sessionvalues sv ON sv.employeeid = e.employeeid
                            LEFT JOIN factory f ON f.factoryid = sv.factoryid
                            LEFT JOIN Workcenter w ON w.workcenterid = sv.workcenterid
                            LEFT JOIN teamemployee te ON te.employeeid = e.employeeid
                            LEFT JOIN team t ON t.teamid = te.teamid
                            LEFT JOIN shift s ON s.shiftid = t.shiftid
                            LEFT JOIN employeerole er ON er.employeeid = e.employeeid
                            LEFT JOIN Roledef rd ON rd.roleid = er.roleid
                            WHERE 1=1  ";
            sql += string.Format(" AND e.employeeid = '{0}' ", context.Request.Form["uid"]);
            DataTable dt = dal.GetDataTable(sql);

            DataTable dtResult = dt.DefaultView.ToTable(true,
                "employeeid", "employeename", "fullname", "factoryname", "factoryid",
                "workcentername", "workcenterid", "shiftname", "shiftid", "teamname", "teamid");

            dtResult.Columns.Add("ROLENAME", typeof(string));

            foreach (DataRow dr in dtResult.Rows)
            {
                if (dt.Select("rolename='定额员'").Length > 0)
                {
                    dr["ROLENAME"] = "管理员";
                    break;
                }
                if (dt.Select("rolename='系统管理员'").Length > 0)
                {
                    dr["ROLENAME"] = "管理员";
                    break;
                }
                if (dt.Select("rolename='分厂领导'").Length > 0)
                {
                    dr["ROLENAME"] = "管理员";
                    break;
                }
                if (dr["factoryname"].ToString() == "")
                {
                    dr["ROLENAME"] = "管理员";
                    break;
                }
                if (dt.Select("rolename='工区长'").Length > 0)
                {
                    if (dr["workcentername"].ToString() == "")
                    {
                        dr["ROLENAME"] = "管理员";
                        break;
                    }
                    else
                    {
                        dr["ROLENAME"] = "工区长";
                        break;
                    }
                }
                if (dt.Select("rolename='班长'").Length > 0)
                {
                    if (dr["shiftname"].ToString() == "")
                    {
                        if (dr["workcentername"].ToString() != "")
                        {
                            dr["ROLENAME"] = "工区长";
                            break;
                        }
                        else
                        {
                            dr["ROLENAME"] = "管理员";
                            break;
                        }
                    }
                    else
                    {
                        dr["ROLENAME"] = "班长";
                        break;
                    }
                }
                if (dt.Select("rolename='组长'").Length > 0)
                {
                    if (dr["teamname"].ToString() == "")
                    {
                        if (dr["shiftname"].ToString() == "")
                        {
                            if (dr["workcentername"].ToString() == "")
                            {
                                dr["ROLENAME"] = "管理员";
                                break;
                            }
                            else
                            {
                                dr["ROLENAME"] = "工区长";
                                break;
                            }
                        }
                        else
                        {
                            dr["ROLENAME"] = "班长";
                            break;
                        }
                    }
                    else
                    {
                        dr["ROLENAME"] = "组长";
                        break;
                    }
                }
                if (dt.Select("rolename='工人'").Length > 0)
                {
                    dr["ROLENAME"] = "工人";
                    break;
                }
            }

            var json = JsonConvert.SerializeObject(dtResult);
            context.Response.ContentType = "text/json";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
        //查询机型
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetProductFamily")
        {
            DataTable dt = cm.GetProductFamily();
            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            context.Response.Write(json.ToString());
            context.Response.End();
        }

        //查询分厂
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetFactory")
        {
            string factoryid = EncryptAndDecryptTool.DesDecrypt(context.Request.Form["factoryid"]);
            string sql = string.Format("SELECT f.factoryname,f.factoryid FROM factory f WHERE f.factoryid = '{0}'", factoryid);
            DataTable dt = dal.GetDataTable(sql);
            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
        //查询工区
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetWorkcenter")
        {
            string factoryid = EncryptAndDecryptTool.DesDecrypt(context.Request.Form["factoryid"]);
            string sql = string.Format("SELECT w.workcenterid,w.workcentername FROM workcenter w WHERE w.notes is null and w.factoryid = '{0}'", factoryid);
            DataTable dt = dal.GetDataTable(sql);
            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
        //查询班（Shift）
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetShift")
        {
            string factoryid = EncryptAndDecryptTool.DesDecrypt(context.Request.Form["factoryid"]);
            string sql = @"SELECT s.shiftid,s.shiftname
                           FROM shift s
                           LEFT JOIN workcenter w ON s.workcenterid = w.workcenterid
                           WHERE 1=1 ";

            sql += string.Format(" AND w.factoryid = '{0}'", factoryid);

            if (context.Request.Form["workcenterid"] != null && context.Request.Form["workcenterid"] != "")
            {
                sql += string.Format(" AND w.workcenterid = '{0}'", context.Request.Form["workcenterid"]);
            }

            DataTable dt = dal.GetDataTable(sql);
            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
        //查询组（Team）
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetTeam")
        {
            string factoryid = EncryptAndDecryptTool.DesDecrypt(context.Request.Form["factoryid"]);
            string sql = @"SELECT t.teamid,t.teamname
                           FROM team t
                           LEFT JOIN shift s ON t.shiftid = s.shiftid
                           LEFT JOIN workcenter w ON w.workcenterid = s.workcenterid
                           WHERE 1=1 ";

            sql += string.Format(" AND w.factoryid = '{0}'", factoryid);

            if (context.Request.Form["workcenterid"] != null && context.Request.Form["workcenterid"] != "")
            {
                sql += string.Format(" AND w.workcenterid = '{0}'", context.Request.Form["workcenterid"]);
            }

            if (context.Request.Form["shiftid"] != null && context.Request.Form["shiftid"] != "")
            {
                sql += string.Format(" AND s.shiftid = '{0}'", context.Request.Form["shiftid"]);
            }

            DataTable dt = dal.GetDataTable(sql);
            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
        //查询员工（Team）
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetEmp")
        {
            string factoryid = EncryptAndDecryptTool.DesDecrypt(context.Request.Form["factoryid"]);
            string sql = @" SELECT e.employeeid,e.employeename,e.fullname
                            FROM employee e
                            LEFT JOIN Sessionvalues sv ON sv.employeeid = e.employeeid
                            LEFT JOIN teamemployee te ON te.employeeid = e.employeeid
                            LEFT JOIN team t ON t.teamid = te.teamid
                            LEFT JOIN shift s ON s.shiftid = t.shiftid 
                            WHERE 1=1 ";

            sql += string.Format(" AND sv.factoryid = '{0}'", factoryid);

            if (context.Request.Form["workcenterid"] != null && context.Request.Form["workcenterid"] != "")
            {
                sql += string.Format(" AND sv.workcenterid = '{0}'", context.Request.Form["workcenterid"]);
            }

            if (context.Request.Form["shiftid"] != null && context.Request.Form["shiftid"] != "")
            {
                sql += string.Format(" AND s.shiftid = '{0}'", context.Request.Form["shiftid"]);
            }

            if (context.Request.Form["teamid"] != null && context.Request.Form["teamid"] != "")
            {
                sql += string.Format(" AND t.teamid = '{0}'", context.Request.Form["teamid"]);
            }

            DataTable dt = dal.GetDataTable(sql);
            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
        //查询分厂【工时分值】属性值
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetGSFZ")
        {
            string factoryid = EncryptAndDecryptTool.DesDecrypt(context.Request.Form["factoryid"]);
            string sql = @" SELECT f.factoryname,f.factoryid,NVL(t.attributevalue,1) attributevalue
                            FROM factory f
                            LEFT JOIN (
                                         SELECT f.factoryid,u.attributevalue
                                         FROM Factory f
                                         LEFT JOIN Userattribute u ON u.parentid=f.factoryid AND u.userattributename='工时分值'
                                      ) t ON t.factoryid = f.factoryid
                            WHERE 1=1 ";
            sql += string.Format(" AND f.factoryid = '{0}'", factoryid);

            DataTable dt = dal.GetDataTable(sql);
            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
        //查询工时
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetWorkTime")
        {
            string factoryid = EncryptAndDecryptTool.DesDecrypt(context.Request.Form["factoryid"]);
            Dictionary<string, object> para = new Dictionary<string, object>();

            if (context.Request.Form["workcenterid"] != null && context.Request.Form["workcenterid"] != "空")
            {
                para["workcenterid"] = context.Request.Form["workcenterid"];
            }
            if (context.Request.Form["shiftid"] != null && context.Request.Form["shiftid"] != "空")
            {
                para["shiftid"] = context.Request.Form["shiftid"];
            }
            if (context.Request.Form["teamid"] != null && context.Request.Form["teamid"] != "空")
            {
                para["teamid"] = context.Request.Form["teamid"];
            }
            if (context.Request.Form["employeeid"] != null && context.Request.Form["employeeid"] != "空")
            {
                para["employeeid"] = context.Request.Form["employeeid"];
            }
            //发动机号
            if (context.Request.Form["engineno"] != null && context.Request.Form["engineno"] != "空")
            {
                para["engineno"] = context.Request.Form["engineno"];
            }
            if (context.Request.Form["productname"] != null && context.Request.Form["productname"] != "空")
            {
                para["productname"] = context.Request.Form["productname"];
            }
            if (context.Request.Form["startDate"] != null)
            {
                para["startDate"] = context.Request.Form["startDate"] + " 00:00:00";
            }
            if (context.Request.Form["endDate"] != null)
            {
                para["endDate"] = context.Request.Form["endDate"] + " 23:59:59";
            }
            if (context.Request.Form["ddlType"] != null)
            {
                para["ddlType"] = context.Request.Form["ddlType"];
            }
            //工时状态
            if (context.Request.Form["status"] != null)
            {
                para["status"] = context.Request.Form["status"];
            }

            decimal gsfz = 1;
            if (context.Request.Form["gsfz"] != null)
            {
                gsfz = Convert.ToDecimal(context.Request.Form["gsfz"]);
            }

            DataTable dtParent = new DataTable();

            if (para["ddlType"].ToString() == "油封工时")
            {
                dtParent = wipDll.GetOilSealWorkTimeData(para);
            }
            if (para["ddlType"].ToString() == "试车工时")
            {
                dtParent = wipDll.GetZsShiCheWorkTimeData(para);//试车工时
            }
            if (para["ddlType"].ToString() == "批产工时" || para["ddlType"].ToString() == "施工工时")
            {
                dtParent = wipDll.GetEmployeeWorkTimeZS(para);//批产、施工工时
            }
            if (para["ddlType"].ToString() == "全部")
            {
                DataTable dtOil = wipDll.GetOilSealWorkTimeData(para);
                dtOil = dtOil.DefaultView.ToTable(false, "employeeid", "fullname", "employeename", "employeeworktime");

                DataTable dtShiChe = wipDll.GetZsShiCheWorkTimeData(para);
                dtShiChe = dtShiChe.DefaultView.ToTable(false, "employeeid", "fullname", "employeename", "employeeworktime");

                dtParent = wipDll.GetEmployeeWorkTimeZS(para);

                dtParent.Merge(dtOil);
                dtParent.Merge(dtShiChe);
            }

            DataTable dtSum = dtParent.DefaultView.ToTable(true, "employeeid", "fullname", "employeename");
            dtSum.Columns.Add("employeeworktime", typeof(System.Double));
            dtSum.Columns.Add("TotalJX", typeof(System.Double));//绩效工时

            string EmployeeId = string.Empty;
            object obj = null;

            string worktimeSum = "0";
            string jxWorkTimeSum = "0";

            foreach (DataRow dr in dtSum.Rows)
            {
                EmployeeId = dr["EmployeeId"].ToString();
                if (EmployeeId == string.Empty)
                {
                    continue;
                }
                obj = dtParent.Compute("sum(employeeworktime)", string.Format("employeeid='{0}'", EmployeeId));
                if (obj != null)
                {
                    dr["employeeworktime"] = obj.ToString();
                    //计算绩效工时
                    dr["TotalJX"] = (Convert.ToDecimal(obj.ToString()) * gsfz).ToString();
                }
            }

            dtSum.AcceptChanges();

            if (dtSum.Rows.Count > 0)
            {
                obj = dtSum.Compute("sum(employeeworktime)", "1=1");
                Object obj2 = dtSum.Compute("sum(TotalJX)", "1=1");
                if (obj != null)
                {
                    worktimeSum = Convert.ToDecimal(obj.ToString()).ToString();
                }
                if (obj2 != null)
                {
                    jxWorkTimeSum = Convert.ToDecimal(obj2.ToString()).ToString();
                }
            }

            var json = JsonConvert.SerializeObject(dtSum);

            json = "{\"data\":" + json.ToString()
                    + ",\"count\":" + dtSum.Rows.Count
                    + ",\"code\":" + "0"
                    + ",\"msg\":" + "0"
                    + ",\"totalGS\":" + worktimeSum
                    + ",\"totalJXGS\":" + jxWorkTimeSum
                    + "}";

            context.Response.ContentType = "text/json";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
        //工时明细
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetWorkTimeDetails")
        {
            string factoryid = EncryptAndDecryptTool.DesDecrypt(context.Request.Form["factoryid"]);
            Dictionary<string, object> para = new Dictionary<string, object>();
            if (context.Request.Form["workcenterid"] != null && context.Request.Form["workcenterid"] != "空")
            {
                para["workcenterid"] = context.Request.Form["workcenterid"];
            }
            if (context.Request.Form["shiftid"] != null && context.Request.Form["shiftid"] != "空")
            {
                para["shiftid"] = context.Request.Form["shiftid"];
            }
            if (context.Request.Form["teamid"] != null && context.Request.Form["teamid"] != "空")
            {
                para["teamid"] = context.Request.Form["teamid"];
            }
            if (context.Request.Form["employeeid"] != null && context.Request.Form["employeeid"] != "空")
            {
                para["employeeid"] = context.Request.Form["employeeid"];
            }
            //发动机号
            if (context.Request.Form["engineno"] != null && context.Request.Form["engineno"] != "空")
            {
                para["engineno"] = context.Request.Form["engineno"];
            }
            if (context.Request.Form["productname"] != null && context.Request.Form["productname"] != "空")
            {
                para["productname"] = context.Request.Form["productname"];
            }
            if (context.Request.Form["startDate"] != null)
            {
                para["startDate"] = context.Request.Form["startDate"] + " 00:00:00";
            }
            if (context.Request.Form["endDate"] != null)
            {
                para["endDate"] = context.Request.Form["endDate"] + " 23:59:59";
            }
            if (context.Request.Form["ddlType"] != null)
            {
                para["ddlType"] = context.Request.Form["ddlType"];
            }
            //工时状态
            if (context.Request.Form["status"] != null)
            {
                para["status"] = context.Request.Form["status"];
            }
            if (context.Request.Form["page"] != null)
            {
                para["page"] = context.Request.Form["page"].ToString();
            }
            if (context.Request.Form["rows"] != null)
            {
                para["rows"] = context.Request.Form["rows"].ToString();
            }

            decimal gsfz = 1;
            if (context.Request.Form["gsfz"] != null)
            {
                gsfz = Convert.ToDecimal(context.Request.Form["gsfz"]);
            }

            int pagecount = 0;
            int rowCount = 0;

            DataTable dtWorkTimeDetails = new DataTable();

            if (para["ddlType"].ToString() == "油封工时")
            {
                dtWorkTimeDetails = wipDll.GetOilSealWorkTimeDataDetails(para, out pagecount, out rowCount);
            }
            if (para["ddlType"].ToString() == "试车工时")
            {
                dtWorkTimeDetails = wipDll.GetZsShiCheWorkTimeDetailsData(para, out pagecount, out rowCount);
            }
            if (para["ddlType"].ToString() == "批产工时" || para["ddlType"].ToString() == "施工工时")
            {
                dtWorkTimeDetails = wipDll.GetEmployeeWorkTimeDetailsZS(para, out pagecount, out rowCount);//批产、任务单工时
            }

            var json = JsonConvert.SerializeObject(dtWorkTimeDetails);
            context.Response.ContentType = "text/json";

            json = "{\"data\":" + json.ToString()
                    + ",\"count\":" + rowCount
                    + ",\"code\":" + "0"
                    + ",\"msg\":" + "0"
                    + "}";

            context.Response.Write(json.ToString());
            context.Response.End();
        }

        //导出前判断是否为空表
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetIsEmpty")
        {
            string factoryid = EncryptAndDecryptTool.DesDecrypt(context.Request.Form["factoryid"]);
            Dictionary<string, object> para = new Dictionary<string, object>();
            if (context.Request.Form["workcenterid"] != null && context.Request.Form["workcenterid"] != "空")
            {
                para["workcenterid"] = context.Request.Form["workcenterid"];
            }

            if (context.Request.Form["shiftid"] != null && context.Request.Form["shiftid"] != "空")
            {
                para["shiftid"] = context.Request.Form["shiftid"];
            }

            if (context.Request.Form["teamid"] != null && context.Request.Form["teamid"] != "空")
            {
                para["teamid"] = context.Request.Form["teamid"];
            }

            if (context.Request.Form["employeeid"] != null && context.Request.Form["employeeid"] != "空")
            {
                para["employeeid"] = context.Request.Form["employeeid"];
            }

            //发动机号
            if (context.Request.Form["engineno"] != null && context.Request.Form["engineno"] != "空")
            {
                para["engineno"] = context.Request.Form["engineno"];
            }
            if (context.Request.Form["productname"] != null && context.Request.Form["productname"] != "空")
            {
                para["productname"] = context.Request.Form["productname"];
            }
            if (context.Request.Form["startDate"] != null)
            {
                para["startDate"] = context.Request.Form["startDate"] + " 00:00:00";
            }
            if (context.Request.Form["endDate"] != null)
            {
                para["endDate"] = context.Request.Form["endDate"] + " 23:59:59";
            }
            if (context.Request.Form["ddlType"] != null)
            {
                para["ddlType"] = context.Request.Form["ddlType"];
            }
            //工时状态
            if (context.Request.Form["status"] != null)
            {
                para["status"] = context.Request.Form["status"];
            }

            DataTable dtParent = new DataTable();

            if (para["ddlType"].ToString() == "油封工时")
            {
                dtParent = wipDll.GetOilSealWorkTimeData(para);
            }
            if (para["ddlType"].ToString() == "试车工时")
            {
                dtParent = wipDll.GetZsShiCheWorkTimeData(para);//试车工时
            }
            if (para["ddlType"].ToString() == "批产工时" || para["ddlType"].ToString() == "施工工时")
            {
                dtParent = wipDll.GetEmployeeWorkTimeZS(para);//批产、施工工时
            }
            if (para["ddlType"].ToString() == "全部")
            {
                DataTable dtOil = wipDll.GetOilSealWorkTimeData(para);
                dtOil = dtOil.DefaultView.ToTable(false, "employeeid", "fullname", "employeename", "employeeworktime");

                DataTable dtShiChe = wipDll.GetZsShiCheWorkTimeData(para);
                dtShiChe = dtShiChe.DefaultView.ToTable(false, "employeeid", "fullname", "employeename", "employeeworktime");

                dtParent = wipDll.GetEmployeeWorkTimeZS(para);

                dtParent.Merge(dtOil);
                dtParent.Merge(dtShiChe);
            }

            DataTable dtSum = dtParent.DefaultView.ToTable(true, "employeeid", "fullname", "employeename");

            var json = JsonConvert.SerializeObject(dtSum);

            json = "{\"count\":" + dtSum.Rows.Count + "}";

            context.Response.ContentType = "text/json";
            context.Response.Write(json.ToString());
            context.Response.End();
        }

        //导出
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "print")
        {
            string factoryid = EncryptAndDecryptTool.DesDecrypt(context.Request.QueryString["factoryid"]);
            Dictionary<string, object> para = new Dictionary<string, object>();

            if (context.Request.QueryString["workcenterid"] != null && context.Request.QueryString["workcenterid"] != "空")
            {
                para["workcenterid"] = context.Request.QueryString["workcenterid"];
            }

            if (context.Request.QueryString["shiftid"] != null && context.Request.QueryString["shiftid"] != "空")
            {
                para["shiftid"] = context.Request.QueryString["shiftid"];
            }
            if (context.Request.QueryString["teamid"] != null && context.Request.QueryString["teamid"] != "空")
            {
                para["teamid"] = context.Request.QueryString["teamid"];
            }
            if (context.Request.QueryString["employeeid"] != null && context.Request.QueryString["employeeid"] != "空")
            {
                para["employeeid"] = context.Request.QueryString["employeeid"];
            }
            //发动机号
            if (context.Request.QueryString["engineno"] != null && context.Request.QueryString["engineno"] != "空")
            {
                para["engineno"] = context.Request.QueryString["engineno"];
            }
            if (context.Request.QueryString["productname"] != null && context.Request.QueryString["productname"] != "空")
            {
                para["productname"] = context.Request.QueryString["productname"];
            }
            if (context.Request.QueryString["startDate"] != null)
            {
                para["startDate"] = context.Request.QueryString["startDate"] + " 00:00:00";
            }
            if (context.Request.QueryString["endDate"] != null)
            {
                para["endDate"] = context.Request.QueryString["endDate"] + " 23:59:59";
            }
            if (context.Request.QueryString["ddlType"] != null)
            {
                para["ddlType"] = context.Request.QueryString["ddlType"];
            }
            //工时状态
            if (context.Request.QueryString["status"] != null)
            {
                para["status"] = context.Request.QueryString["status"];
            }

            decimal gsfz = 1;
            if (context.Request.QueryString["gsfz"] != null)
            {
                gsfz = Convert.ToDecimal(context.Request.QueryString["gsfz"]);
            }

            DataTable dtParent = new DataTable();

            if (para["ddlType"].ToString() == "油封工时")
            {
                dtParent = wipDll.GetOilSealWorkTimeData(para);
            }
            if (para["ddlType"].ToString() == "试车工时")
            {
                dtParent = wipDll.GetZsShiCheWorkTimeData(para);//试车工时
            }
            if (para["ddlType"].ToString() == "批产工时" || para["ddlType"].ToString() == "施工工时")
            {
                dtParent = wipDll.GetEmployeeWorkTimeZS(para);//批产、施工工时
            }
            if (para["ddlType"].ToString() == "全部")
            {
                DataTable dtOil = wipDll.GetOilSealWorkTimeData(para);
                dtOil = dtOil.DefaultView.ToTable(false, "employeeid", "fullname", "employeename", "employeeworktime");

                DataTable dtShiChe = wipDll.GetZsShiCheWorkTimeData(para);
                dtShiChe = dtShiChe.DefaultView.ToTable(false, "employeeid", "fullname", "employeename", "employeeworktime");

                dtParent = wipDll.GetEmployeeWorkTimeZS(para);

                dtParent.Merge(dtOil);
                dtParent.Merge(dtShiChe);
            }

            DataTable dtMain = dtParent.DefaultView.ToTable(true, "employeeid", "fullname", "employeename");
            dtMain.Columns.Add("employeeworktime", typeof(System.Double));
            dtMain.Columns.Add("TotalJX", typeof(System.Double));//绩效工时

            string EmployeeId = string.Empty;
            object obj = null;

            foreach (DataRow dr in dtMain.Rows)
            {
                EmployeeId = dr["EmployeeId"].ToString();
                if (EmployeeId == string.Empty)
                {
                    continue;
                }
                obj = dtParent.Compute("sum(employeeworktime)", string.Format("employeeid='{0}'", EmployeeId));
                if (obj != null)
                {
                    dr["employeeworktime"] = obj.ToString();
                    //计算绩效工时
                    dr["TotalJX"] = (Convert.ToDecimal(obj.ToString()) * gsfz).ToString();
                }
            }

            DataTable dtDetail = new DataTable();

            if (para["ddlType"].ToString() != "全部")
            {
                dtDetail = wipDll.ExportEmployeeWorkTimeZS(para);

                ExportHelper.ExportExcel(wipDll.CombainTable(dtMain, dtDetail), "装配试车厂工时统计报表");
            }
            else
            {
                ExportHelper.ExportExcel(wipDll.CombainTable(dtMain, dtDetail), "装配试车厂工时统计报表");
            }
        }
    }
}